<?php
namespace App\Models\DyModels;
use App\Models\ParentModel;
use DB;
/**
 * 抖音同步信息表model
 * @author puppet
 */
class Infosync extends ParentModel{
  /**
   * 与模型关联的数据表。
   *
   * @var string
   */
  protected $table = 'pt_dy_infosync';

  /**
   * DB::直接操作的数据库表名
   * @var string
   */
  protected $db_table = 'pt_dy_infosync';

  /**
   * 主键 默认id。
   *
   * @var string
   */
  protected $primaryKey = 'id';

  /**
   * 指定是否模型应该被戳记时间。
   *
   * @var bool
   */
  public $timestamps = false;

	//查询合伙人总数
	function countPt(){
		$sql="select count(id) as count from pt_partner where status!=-1 and type=?";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询会员数
	function countPu(){
		$sql="select count(id) as count from pt_partner where status!=-1 and type=?";
		$re=DB::select($sql,[2]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询授权用户数
	function countUser(){
		$sql="select count(DISTINCT open_id) as count from pt_user where status!=?";
		$re=DB::select($sql,[-1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询达人数
	function countTal(){
		$sql="select count(DISTINCT open_id) as count from pt_talent where tl_status=0 or tl_status=?";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询待审核达人数
	function countTalD(){
		$sql="select count(id) as count from pt_talent where tl_status=?";
		$re=DB::select($sql,[-2]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询最近一天拉取的关键词视频数
	function countVideoDay(){
		$sql="select count(id) as count from pt_keyword_video where 1=? and update_time>='".date('Y-m-d',time()-24*3600)."' and update_time<='".date('Y-m-d',time()-24*3600)." 23:59:59'";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询最近一天拉取的视频评论数
	function countCommentDay(){
		$sql="select count(id) as count from pt_keyword_video_comment where 1=? and update_time>='".date('Y-m-d',time())."'";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//查询最近一天的作品评论数
	function countInfoCommentDay(){
		$sql="select count(id) as count from pt_user_info_comment where 1=? and update_time>='".date('Y-m-d',time()-24*3600)." 22:30:00'";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//主页监控数
	function countUserInfo(){
		$sql="select count(DISTINCT number_id) as count from pt_user_info where info_type=?";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//视频监控数
	function countUserInfoTwo(){
		$sql="select count(DISTINCT number_id) as count from pt_user_info where info_type=?";
		$re=DB::select($sql,[2]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//待审核视频
	function countStayVideo(){
		$sql="select count(id) as count from pt_dy_user_video where status=?";
		$re=DB::select($sql,[0]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//已发布视频
	function countTooVideo(){
		$sql="select count(id) as count from pt_dy_user_video where status=?";
		$re=DB::select($sql,[2]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//开户总额
	function countPrice(){
		$sql="select sum(first_price) as count from pt_partner where type=? and status!=-1";
		$re=DB::select($sql,[1]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//会员总套餐金额
	function countPriceMeal(){
		$sql="select sum(a.price) as count from pt_partner_meal as a left join pt_partner as b on b.id=a.partner_id where b.type=? and b.status!=-1";
		$re=DB::select($sql,[2]);
		return isset($re[0]['count']) ? $re[0]['count'] : false;
	}
	
	//最新10条订单信息
	function orderList(){
		$sql="select a.*,b.user_name from pt_order as a left join pt_partner as b on b.id=a.partner_id where 1=? order by a.create_time desc limit 10";
		$re=DB::select($sql,[1]);
		$re=isset($re[0]['id']) ? $re : false;
		if($re){
			$config=Config('basics');
			foreach($re as $k=>$v){
				$re[$k]['partner_type']=$v['partner_type']==1 ? '合伙人' : '会员';
				$re[$k]['type']=$config['type'][$v['type']];
				$re[$k]['pay_type']=$config['pay_type'][$v['pay_type']];
			}
		}
		return $re;
	}
	
}